/*
 * Copyright 2016 Yan Zhenjie
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mingmen.canting.caigourenyuan;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mingmen.canting.R;
import com.mingmen.canting.activity.FilterLoginRestruantActivity;
import com.mingmen.canting.activity.LoginActivity;
import com.mingmen.canting.activity.RegisterActivity;
import com.mingmen.canting.adapter.FileerFangqiAdapter;
import com.mingmen.canting.adapter.MyLabelAdapter;
import com.mingmen.canting.chushizhang.CaiGouRuKuFagment;
import com.mingmen.canting.jingli.JingLiRukuFragment;
import com.mingmen.canting.util.SharePreferenceUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;


/**
 * <p>
 * ListView形式的侧滑菜单，支持横向和竖向的。
 * </p>
 * Created by Yan Zhenjie on 2016/7/27.
 */
public class FilterFangQiActivity extends Activity {
    @BindView(R.id.img_return)
    ImageView imgReturn;

    @BindView(R.id.layout_close)
    LinearLayout layoutClose;
    @BindView(R.id.text_1)
    TextView text1;
    @BindView(R.id.text_2)
    TextView text2;
    @BindView(R.id.text_3)
    TextView text3;

    String string;
    String attrs = "";
    @BindView(R.id.btn_select)
    Button btn_select;
    String count;
    List<String> dingdan = new ArrayList<>();
    FileerFangqiAdapter myLabelAdapter;
    @BindView(R.id.main_recycler)
    RecyclerView main_recycler;
    int myposition = 0;
    String kuaijie;
    @BindView(R.id.btn_cancel)
    Button btn_cancel;
    String applyDetailId;
    String reason = "";
    @BindView(R.id.checkbox)
    CheckBox checkbox;
    @BindView(R.id.checkbox1)
    CheckBox checkbox1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity__filterfangqi);
        EventBus.getDefault().register(this);
        ButterKnife.bind(this);
        dingdan.add("供应商无货");
        dingdan.add("其他");
      /*  GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        main_recycler.setLayoutManager(gridLayoutManager);*/

        main_recycler.setLayoutManager(new LinearLayoutManager(this));
        myLabelAdapter = new FileerFangqiAdapter(this);
        myLabelAdapter.setDataList(dingdan);
        main_recycler.setAdapter(myLabelAdapter);
        DividerItemDecoration divider = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(this, R.drawable.custom_divider));
        applyDetailId = getIntent().getStringExtra("applyDetailId");
        main_recycler.addItemDecoration(divider);
        myLabelAdapter.setOnItemClickListener(new FileerFangqiAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(View view, int pos, List<String> myLiveList) {
                myLabelAdapter.setCheckedPosition(pos);
                myposition = pos;
                reason = myLiveList.get(pos);

            }
        });
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    reason="供应商无货";
                    checkbox1.setChecked(false);
                }else {

                }
            }
        });
        checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    reason="其他";
                    checkbox.setChecked(false);
                }else {

                }
            }
        });
    }


    @OnClick({R.id.img_return, R.id.layout_close, R.id.text_1, R.id.text_2, R.id.text_3, R.id.btn_select, R.id.btn_cancel})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {

            case R.id.img_return:
            case R.id.layout_close:


                finish();

                break;
            case R.id.text_1:
                text1.setBackground(getResources().getDrawable(R.drawable.shape_label_select));
                text1.setTextColor(Color.parseColor("#BF0B22"));
                text2.setBackground(getResources().getDrawable(R.drawable.shape_label_unselect));
                text2.setTextColor(Color.parseColor("#303030"));
                text3.setBackground(getResources().getDrawable(R.drawable.shape_label_unselect));
                text3.setTextColor(Color.parseColor("#303030"));
                break;
            case R.id.text_2:
                text2.setBackground(getResources().getDrawable(R.drawable.shape_label_select));
                text2.setTextColor(Color.parseColor("#BF0B22"));
                text1.setBackground(getResources().getDrawable(R.drawable.shape_label_unselect));
                text1.setTextColor(Color.parseColor("#303030"));
                text3.setBackground(getResources().getDrawable(R.drawable.shape_label_unselect));
                text3.setTextColor(Color.parseColor("#303030"));
                break;
            case R.id.text_3:
                text3.setBackground(getResources().getDrawable(R.drawable.shape_label_select));
                text3.setTextColor(Color.parseColor("#BF0B22"));
                text2.setBackground(getResources().getDrawable(R.drawable.shape_label_unselect));
                text2.setTextColor(Color.parseColor("#303030"));
                text1.setBackground(getResources().getDrawable(R.drawable.shape_label_unselect));
                text1.setTextColor(Color.parseColor("#303030"));
                break;
            case R.id.btn_select:
                if (reason.equals("")) {
                    Toast.makeText(this, "请选择放弃原因", Toast.LENGTH_SHORT).show();
                } else {
                    intent = new Intent(FilterFangQiActivity.this, DaiCaiGouListfragment.class);
//                intent = new Intent(FilterFangQiActivity.this, CaiGouRenDaiListragment.class);
//                    intent.putExtra("reason", dingdan.get(0));
                    intent.putExtra("reason", reason);
                    intent.putExtra("applyDetailId", applyDetailId);
                    setResult(200, intent);
                    finish();
                }


                break;
            case R.id.btn_cancel:
                finish();
                break;
        }
    }

    public void onEventMainThread(Integer type) {

    }


}